package org.osomit.sacct.session.token.provider;

import com.google.inject.Provider;
import com.google.inject.Inject;
import org.osomit.sacct.session.token.iface.TokenExpirationPolicy;
import org.osomit.sacct.session.token.iface.TokenIdGenerator;
import org.osomit.sacct.session.token.impl.SessionToken;

/**
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 *
 * Date: Jul 1, 2009
 */
public class SessionTokenProvider implements Provider<SessionToken> {

    private TokenExpirationPolicy expirationPolicy;

    private TokenIdGenerator idGenerator;

    public TokenIdGenerator getIdGenerator() {
        return idGenerator;
    }

    @Inject
    public void setIdGenerator(TokenIdGenerator idGenerator) {
        this.idGenerator = idGenerator;
    }

    public TokenExpirationPolicy getExpirationPolicy() {
        return expirationPolicy;
    }

    @Inject
    public void setExpirationPolicy(TokenExpirationPolicy expirationPolicy) {
        this.expirationPolicy = expirationPolicy;
    }

    public SessionToken get() {
        
        return new SessionToken(this.idGenerator.getNewTokenId(SessionToken.PREFIX), this.expirationPolicy);
    }
}
